#!/bin/bash

# Rust Web服务演示项目启动脚本

set -e

echo "🚀 Rust Web服务演示项目启动脚本"
echo "=================================="

# 检查Docker是否安装
if ! command -v docker &> /dev/null; then
    echo "❌ Docker未安装，请先安装Docker"
    exit 1
fi

# 检查Docker Compose是否安装
if ! command -v docker-compose &> /dev/null; then
    echo "❌ Docker Compose未安装，请先安装Docker Compose"
    exit 1
fi

# 检查环境变量文件
if [ ! -f .env ]; then
    echo "📝 创建环境变量文件..."
    cp env.example .env
    echo "✅ 环境变量文件已创建，请根据需要修改 .env 文件"
fi

# 创建必要的目录
echo "📁 创建必要的目录..."
mkdir -p logs data ssl

# 启动服务
echo "🐳 启动Docker服务..."
docker-compose up -d

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 10

# 检查服务状态
echo "📊 检查服务状态..."
docker-compose ps

# 显示访问信息
echo ""
echo "✅ 服务启动完成！"
echo ""
echo "🌐 访问地址："
echo "   - 主应用: http://localhost:3000"
echo "   - 健康检查: http://localhost:3000/health"
echo "   - API文档: http://localhost:3000"
echo "   - WebSocket: ws://localhost:3001/ws"
echo "   - TCP服务器: tcp://localhost:3002"
echo "   - Prometheus: http://localhost:9091"
echo "   - Grafana: http://localhost:3001 (admin/admin)"
echo ""
echo "📝 查看日志："
echo "   docker-compose logs -f app"
echo ""
echo "🛑 停止服务："
echo "   docker-compose down"
echo ""
echo "🔄 重启服务："
echo "   docker-compose restart"
echo ""
echo "📋 默认管理员账户："
echo "   用户名: admin"
echo "   邮箱: admin@example.com"
echo "   密码: admin123"
echo ""
echo "🎉 享受您的Rust Web服务演示项目！"
